package arrowandsphere;

import java.io.*;
import java.net.*;
import java.util.*;

public class SessionApp {
    private static List<Session> sessions = new Vector<Session>();
    
    public static void main(String [] args) throws IOException {
        ServerSocket ss = new ServerSocket(1234);
        while (true) {
            System.out.println("Listening...");
            Socket s = ss.accept();
            System.out.println("Connection from " + s);
            SessionAppThread thread = new SessionAppThread(s);
            thread.start();
        }
    }
    
    public static int createSession(CreateSession c) {
        sessions.add(new Session(c.getNumberOfPlayers()));
        return 0;
    }
    
    public static Session readSession(ReadSession r) {
        return sessions.get(r.getId());
    }
    
    public static List<Session> readSessions(ReadSessions r) {
        return sessions;
    }
    
    public static int updateSession(UpdateSession u) {
        sessions.set(u.getId(), u.getSession());
        return 0;
    }
    
    public static int deleteSession(DeleteSession d) {
        sessions.remove(d.getId());
        return 0;
    }
}
